// mysql/FileUpload.js
const Sequelize = require("sequelize");
const sequelize = require("./index"); // 确保路径正确
const { DataTypes } = Sequelize;

const FileUpload = sequelize.define(
  "FileUpload",
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: "FileUploadID",
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "用户ID",
    },
    fileType: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "filetype",
    },
    bisonId: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "bison⽂件地址id",
    },
    originalFilename: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "原始名称",
    },
    filename: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "本地⽂件",
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
      field: "created_at",
      comment: "记录创建时间",
    },
    updatedAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
      onUpdate: Sequelize.literal("CURRENT_TIMESTAMP"),
      field: "updated_at", // 可选：指定数据库中的字段名
      comment: "记录更新时间",
    },
  },
  {
    tableName: "fileuploads",
    timestamps: true,
  }
);

module.exports = FileUpload;
